﻿using System;
using System.IO;
using System.Windows.Forms;
using App.Modelo.Attributes;

namespace App.Seguridad.Vista.Forms
{
    [Formulario("Ayuda")]
    public partial class Ayuda : Form
    {
        private readonly FormularioPrincipal main = FormularioPrincipal.Instance;
        private string _HelpPath;


        public Ayuda()
        {
            InitializeComponent();
        }

        public string HelpPath
        {
            get
            {
                if (_HelpPath == null)
                    _HelpPath = String.Join(
                        Path.DirectorySeparatorChar.ToString(), new[]
                                                                    {
                                                                        Path.GetDirectoryName(Application.ExecutablePath)
                                                                        ,
                                                                        "ayuda"
                                                                    });
                return _HelpPath;
            }
            set { _HelpPath = value; }
        }

        private void Ayuda_Load(object sender, EventArgs e)
        {
        }

        public Uri GetPage()
        {
            return GetPage("index.html");
        }

        public Uri GetPage(string p)
        {
            var uri = new Uri(HelpPath);

            return new Uri(HelpPath + "/" + p);
        }


        [Comando("ver")]
        public void ver()
        {
            //   main.Move += new EventHandler(main_Move);

            //   main.Left = main.Left - Width / 2;

            //            AlLadoMain();
            webBrowser1.Url = GetPage();


            Show();
        }

        private void main_Move(object sender, EventArgs e)
        {
            AlLadoMain();
        }

        private void AlLadoMain()
        {
            if (main.WindowState == FormWindowState.Normal)
            {
                Left = main.Left + main.Width;
                Top = main.Top;
                Height = main.Height;
            }
        }

        private void Ayuda_FormClosed(object sender, FormClosedEventArgs e)
        {
            main.Centrar();
        }
    }
}